/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* SdProjectUniversalChangeService
* 项目变更通用
*
* 修改纪录
* 2021-12-20 版本：1.0 wangxinhua 创建。
* @version 版本：1.0
* @author 作者：wangxinhua
* 创建日期：2021-12-20
*/
package com.topscomm.gpm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.util.PrimaryKeyUtil;
import com.topscomm.cbo.pojo.*;
import com.topscomm.cbo.service.ICboMessageAppService;
import com.topscomm.cbo.service.ICboMessageSysService;
import com.topscomm.cbo.service.impl.CboApprovalNodeInsService;
import com.topscomm.mis.constant.MisSystemConst;
import com.topscomm.mis.mobile.message.service.SendMessageService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.gpm.GpmSystemConst;
import com.topscomm.gpm.pojo.*;
import com.topscomm.gpm.service.*;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.common.ParameterCache;
import com.topscomm.tap.common.SessionUserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.gpm.service.impl.auto.GpmProjectUniversalChangeServiceAuto;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.topscomm.gpm.GpmSystemConst.*;

@Service(value = "gpmProjectUniversalChangeService")
@Scope(value = "singleton")
public class GpmProjectUniversalChangeService extends GpmProjectUniversalChangeServiceAuto implements IGpmProjectUniversalChangeService {
    @Autowired
    private IGpmProjectService gpmProjectService;

    @Autowired
    private ICboMessageAppService cboMessageAppService;

    @Autowired
    private ICboMessageSysService cboMessageSysService;

    @Autowired
    private IGpmProjectHistoryService gpmProjectHistoryService;

    @Autowired
    private IGpmProjectAppointmentService gpmProjectAppointmentService;

    @Autowired
    private IGpmProjectPlanService gpmProjectPlanService;

    @Autowired
    private IGpmWfFormService gpmWfFormService;

    @Autowired
    private CboApprovalNodeInsService cboApprovalNodeInsService;

    @Autowired
    private SendMessageService sendMessageService;

    /**
     * @author: chengengwei
     * @date: 2021-08-18
     * @param entity
     * @description:单号生成
     * @modify:
     */
    @Override
    protected void beforeInsert(BasicEntity entity) {
        super.beforeInsert(entity);
        if (entity.getId() <= 0) {// 赋值Id和单号
            long[] arrayId = PrimaryKeyUtil.GeneIDs(entity.getTableName(), 1);
            entity.setId(arrayId[0]);
            String docNo = String.valueOf(arrayId[0]);
            docNo = docNo.substring(0, 6) + docNo.substring(9);
            entity.setValue(GpmProjectUniversalChangeEntity.FieldDocno, docNo);
            GpmProjectUniversalChangeEntity changeEntity = (GpmProjectUniversalChangeEntity) entity;
            String changeCode = "BG";
            SimpleDateFormat sdFormat = new SimpleDateFormat("yyMMdd");
            String dateCode = sdFormat.format(new Date());
            String flowCode = docNo.substring(docNo.length() - 3);
            changeCode = changeCode + dateCode + flowCode;
            entity.setValue(GpmProjectUniversalChangeEntity.FieldChangecode, changeCode);
        }
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-19
     * @description: 项目经理保存意见和审批人
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveApprovalUserAndOpinion(Map<String, Object> paraMap) {
        String id = ConvertUtil.convertToString(paraMap.get("applyid"));
        GpmProjectUniversalChangeEntity changeEntity = this.queryById(id);
        // 先将approvalusercodes和approvalusernames字段置空
        changeEntity.setAddapprovalusercodes("");
        changeEntity.setAddapprovalusernames("");
        // 保存审批人
        if (paraMap.containsKey("addapprovalusercodes") && !StringUtil.isEmpty(ConvertUtil
                .convertToString(paraMap.get("addapprovalusercodes")))) {
            this.setApprovalUser(changeEntity, paraMap);
        }
        // 保存项目经理意见
        this.setManagerOpinion(changeEntity, paraMap);
        this.updateEntity(changeEntity);
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-19
     * @description: 保存审批人
     * @modify:
     */
    private void setApprovalUser(GpmProjectUniversalChangeEntity changeEntity, Map<String, Object> paraMap) {
        String addapprovalusercodes = "," + ConvertUtil.convertToString(paraMap.get("addapprovalusercodes")) + ",";
        String addapprovalusernames = ConvertUtil.convertToString(paraMap.get("addapprovalusernames"));
        // 将变更记录的addapprovalusercodes、addapprovalusernames覆盖，更新allapprovalusercodes、allapprovalusernames
        String allapprovalusercodes = changeEntity.getAllapprovalusercodes();
        String allapprovalusernames = changeEntity.getAllapprovalusernames();
        // 如果oldallapprovalusercodes不为空则说明不是第一次选择审批人
        if (!StringUtil.isEmpty(allapprovalusercodes)) {
            String[] allCodesArr = allapprovalusercodes.split(",");
            String[] allNamesArr = allapprovalusernames.split(",");
            String[] addCodesArr = addapprovalusercodes.split(",");
            String[] addNamesArr = addapprovalusernames.split(",");
            // 将新增审批人加入到所有审批人前先去重
            allapprovalusercodes = "," + Stream.concat(Stream.of(allCodesArr), Stream.of(addCodesArr)
                    .filter(item -> !StringUtil.isEmpty(item))).distinct().collect(Collectors.joining(",")) + ",";
            allapprovalusernames = Stream.concat(Stream.of(allNamesArr), Stream.of(addNamesArr)
                    .filter(item -> !StringUtil.isEmpty(item))).distinct().collect(Collectors.joining(","));
        } else {
            allapprovalusercodes = addapprovalusercodes;
            allapprovalusernames = addapprovalusernames;
        }
        changeEntity.setAddapprovalusercodes(addapprovalusercodes);
        changeEntity.setAddapprovalusernames(addapprovalusernames);
        changeEntity.setAllapprovalusercodes(allapprovalusercodes);
        changeEntity.setAllapprovalusernames(allapprovalusernames);
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-19
     * @description: 保存项目经理意见
     * @modify:
     */
    private void setManagerOpinion(GpmProjectUniversalChangeEntity changeEntity, Map<String, Object> paraMap) {
        // 如果paraMap的KeySet包含opinion但Value为空则默认赋“同意”
        if (paraMap.containsKey("opinion")) {
            String opinion = ConvertUtil.convertToString(paraMap.get("opinion"));
            if (!StringUtil.isEmpty(opinion)) {
                changeEntity.setProjectmanageropinion(opinion);
            } else if (StringUtil.isEmpty(changeEntity.getProjectmanageropinion())) {
                changeEntity.setProjectmanageropinion("同意");
            }
        }
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-20
     * @description: 审批后保存意见
     * @modify:
     */
    @Override
    protected void afterApprove(TapEntity billEntity, CboApprovalNodeInsEntity nodeIns, CboApprovalNodeEntity node,
                                SessionUserBean sessionUserBean) {
        String selectNodeId = ParameterCache.getValue(SelectApprovalUserNodeId, "0");
        String comfirmNodeId = ParameterCache.getValue(StakeholderComfirmNodeId, "0");
        // 选择审批人节点
        if (selectNodeId.equals(ConvertUtil.convertToString(node.getId()))) {
            Map<String, Object> paraMap = new HashMap<>();
            paraMap.put("opinion", nodeIns.getApprovalopinion());
            this.setManagerOpinion((GpmProjectUniversalChangeEntity) billEntity, paraMap);
            this.updateEntity(billEntity);
        } else if (comfirmNodeId.equals(ConvertUtil.convertToString(node.getId()))) {// 相关方确认节点
            // 将新增审批人信息置为空
            ((GpmProjectUniversalChangeEntity)billEntity).setAddapprovalusercodes("");
            ((GpmProjectUniversalChangeEntity)billEntity).setAddapprovalusernames("");
            this.saveOpinion((GpmProjectUniversalChangeEntity) billEntity, nodeIns.getApprovalopinion());
        }
        super.afterApprove(billEntity, nodeIns, node, sessionUserBean);
    }
    /**
     * @author: chengengwei
     * @date: 2021-08-20
     * @description: 保存除项目经理外其他人意见
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOpinion(GpmProjectUniversalChangeEntity changeEntity, String opinion) {
        // 查询项目信息
        List<GpmProjectEntity> mpmProjectEntities = this.gpmProjectService.queryByWhere(" projectcode = '"
                + changeEntity.getProjectcode() + "' ");
        StringBuffer resultOpinion = new StringBuffer();
        if (!mpmProjectEntities.isEmpty()) {
            GpmProjectEntity mpmProjectEntity = mpmProjectEntities.get(0);
            // 当前用户code
            CboUserEntity user = getSessionUserBean().getUser();
            // 判断是否是owner
            if (user.getCode().equals(mpmProjectEntity.getOwnercode())) {
                // 已经保存过owner意见则换行
                if (!StringUtil.isEmpty(changeEntity.getOwneropinion())) {
                    resultOpinion.append(changeEntity.getOwneropinion() + "\n");
                }
                // 意见为空默认赋值“同意”
                if (StringUtil.isEmpty(opinion)) {
                    resultOpinion.append("同意");
                } else {
                    resultOpinion.append(opinion);
                }
                changeEntity.setOwneropinion(resultOpinion.toString());
            } else {
                if (!StringUtil.isEmpty(changeEntity.getStakeholderopinion())) {
                    resultOpinion.append(changeEntity.getStakeholderopinion() + "\n");
                }
                // 拼接当前用户信息
                resultOpinion.append(user.getName() + "【" + user.getCode() + "】：");
                // 意见为空默认赋值“同意”
                if (StringUtil.isEmpty(opinion)) {
                    resultOpinion.append("同意");
                } else {
                    resultOpinion.append(opinion);
                }
                changeEntity.setStakeholderopinion(resultOpinion.toString());
            }
        }
        this.updateEntity(changeEntity);
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-20
     * @description: 保存除项目经理外其他人意见
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void sendMessageToPMO(GpmProjectUniversalChangeEntity changeEntity) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("projectcode", changeEntity.getProjectcode());
        List<Map<String, Object>> queryPMOList = this.queryMap(paramMap, "queryPMO");
        if (!queryPMOList.isEmpty()) {
            CboUserEntity PMOEntity = new CboUserEntity();
            // 把结果集包装成CboUserEntity
            PMOEntity.convertFromMap(queryPMOList.get(0));
            // 消息内容
            String content = String.format(RemindPMOMessageContent, changeEntity.getProjectname());
            Map<String, Object> appMap = new HashMap<>();
            // 给PMO发送APP消息
            appMap.put(CboMessageAppEntity.FieldSourceid, changeEntity.getId());
            appMap.put(CboMessageAppEntity.FieldSourcetype, GpmProjectUniversalChangeEntity.tableName);
            appMap.put("state", 0);
            appMap.put(CboMessageAppEntity.FieldSendcount, 0);
//            appMap.put("usercode", PMOEntity.getCode());
            appMap.put(CboMessageAppEntity.FieldContent, content);
            appMap.put(CboMessageAppEntity.FieldExtendfield1, RemindPMOMessageSubject);
            appMap.put("messagetype", MisSystemConst.MobileMessageType.OTHER_TYPE);
            appMap.put("receivercode", PMOEntity.getCode());
            appMap.put("receivername", PMOEntity.getName());

//            this.cboMessageAppService.insertMap(appMap);
            sendMessageService.sendAppMessage(appMap);
            // 给PMO发送系统提醒
            Map<String, Object> sysMap = new HashMap<>();
            sysMap.put(CboMessageSysEntity.FieldSourceid, changeEntity.getId());
            sysMap.put(CboMessageSysEntity.FieldSourcetype, GpmProjectUniversalChangeEntity.tableName);
            sysMap.put(CboMessageSysEntity.FieldReceivercode, PMOEntity.getCode());
            sysMap.put(CboMessageSysEntity.FieldReceivername, PMOEntity.getName());
            sysMap.put("state", 0);
            sysMap.put(CboMessageSysEntity.FieldContent, content);
            sysMap.put(CboMessageSysEntity.FieldSubject, RemindPMOMessageSubject);
            sysMap.put("messagetype", MisSystemConst.MobileMessageType.OTHER_TYPE);
            sendMessageService.sendSysMessage(sysMap);
//            this.cboMessageSysService.insertMap(sysMap);
        }
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-23
     * @description: 立项变更、项目任命、项目策划审批通过后调用该方法生成通用变更记录
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createRecordAfterApproval(String sourcetype, String sourceid, String extendField2) {
        GpmProjectUniversalChangeEntity changeEntity = new GpmProjectUniversalChangeEntity();
        if ("GpmWfForm".equals(sourcetype)) {
            GpmWfFormEntity gpmWfFormEntity = gpmWfFormService.queryById(sourceid);
            if(GpmSystemConst.SdApprovalCategory.SdProjectChange.equals(gpmWfFormEntity.getBusinesstype())) {
                // 变更记录更新状态
                Map<String,Object> changeUpdateMap = new HashMap<String,Object>();
                changeUpdateMap.put(GpmProjectUniversalChangeEntity.FieldState, 1);
                changeUpdateMap.put(GpmProjectUniversalChangeEntity.FieldLatestphase, extendField2);
                this.updateByWhere(changeUpdateMap,"sourceid="+ gpmWfFormEntity.getSourceid() + " and sourcetype='"+ GpmProjectHistoryEntity.tableName +"' and version="
                        + gpmWfFormEntity.getVersion());
            } else {
            }
        } else if (GpmProjectAppointmentEntity.tableName.equals(sourcetype)) {
            // 变更记录来源是项目任命，不是二次任命直接返回
            if (!this.createRecordByAppointment(changeEntity, sourceid, extendField2)) {
            }
        } else if (GpmProjectPlanEntity.tableName.equals(sourcetype)) {
            // 变更记录来源是项目策划，不是二次策划直接返回
            if (!this.createRecordByPlan(changeEntity, sourceid, extendField2)) {
            }
        }
//        this.insert(changeEntity);
    }

    /**
     * @author: wxh
     * @date: 2021-08-23
     * @description: 立项变更、项目任命、项目策划审批通过后调用该方法生成通用变更记录
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createRecordAfterSave(String sourcetype, String sourceid, String extendField2) {
        GpmProjectUniversalChangeEntity changeEntity = new GpmProjectUniversalChangeEntity();
        if (GpmProjectHistoryEntity.tableName.equals(sourcetype)) {
            this.createRecordByChange(changeEntity, sourceid, extendField2);
        } else if (GpmProjectAppointmentEntity.tableName.equals(sourcetype)) {
            // 变更记录来源是项目任命，不是二次任命直接返回
            if (!this.createRecordByAppointment(changeEntity, sourceid, extendField2)) {
                return;
            }
        } else if (GpmProjectPlanEntity.tableName.equals(sourcetype)) {
            // 变更记录来源是项目策划，不是二次策划直接返回
            if (!this.createRecordByPlan(changeEntity, sourceid, extendField2)) {
                return;
            }
        }
        this.insert(changeEntity);
    }
    /**
     * @author: chengengwei
     * @date: 2021-08-23
     * @description: 立项变更审批通过后生成通用变更记录
     * @modify:
     */
    private void createRecordByChange(GpmProjectUniversalChangeEntity changeEntity, String sourceid, String latestphase) {
        GpmProjectHistoryEntity mpmProjectChangeEntity = this.gpmProjectHistoryService.queryById(sourceid);
        //先删除退回的数据
        this.deleteByWhere("sourceid="+sourceid + " and sourcetype='"+ GpmProjectHistoryEntity.tableName +"' and version="
                +mpmProjectChangeEntity.getVersion() + " and state=2");
        //再添加
        changeEntity.setProjectid(mpmProjectChangeEntity.getProjectid());
        changeEntity.setProjectcode(mpmProjectChangeEntity.getProjectcode());
        changeEntity.setProjectmanager(mpmProjectChangeEntity.getProjectmanager());
        changeEntity.setProjectmanagercode(mpmProjectChangeEntity.getProjectmanagercode());
        changeEntity.setProjectname(mpmProjectChangeEntity.getProjectname());
        changeEntity.setChangereason(mpmProjectChangeEntity.getChangereason());
        changeEntity.setLatestphase(latestphase);
        changeEntity.setState(0);
        changeEntity.setSubmitdate(mpmProjectChangeEntity.getCreateon());
        changeEntity.setSourcetype(mpmProjectChangeEntity.getTableName());
        changeEntity.setSourceid(mpmProjectChangeEntity.getId());
        changeEntity.setVersion(mpmProjectChangeEntity.getVersion());
        changeEntity.setUsercode(getSessionUserBean().getUser().getCode());
        changeEntity.setUsername(getSessionUserBean().getUser().getName());
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-23
     * @description: 任命审批通过后生成通用变更记录
     * @modify:
     */
    private boolean createRecordByAppointment(GpmProjectUniversalChangeEntity changeEntity, String sourceid, String latestphase) {
        GpmProjectAppointmentEntity mpmProjectAppointmentEntity = gpmProjectAppointmentService.queryById(sourceid);
        int recordCount = this.getCount("sourceid="+sourceid + " and sourcetype='"+ GpmProjectAppointmentEntity.tableName +"' and version="
                +mpmProjectAppointmentEntity.getVersion() + " and state=2");
        if(recordCount>0) {
            Map<String,Object> updateMap = new HashMap<String,Object>();
            updateMap.put("state",1);
            //先删除退回的数据
            this.updateByWhere(updateMap,"sourceid="+sourceid + " and sourcetype='"+ GpmProjectAppointmentEntity.tableName +"' and version="
                    +mpmProjectAppointmentEntity.getVersion() + " and state=2");
        }
        // 判断是否是二次任命，是二次任命返回true
        return !"1".equals(mpmProjectAppointmentEntity.getSyspush());
    }

    /**
     * @author: chengengwei
     * @date: 2021-08-23
     * @description: 策划审批通过后生成通用变更记录
     * @modify:
     */
    private boolean createRecordByPlan(GpmProjectUniversalChangeEntity changeEntity, String sourceid, String latestphase) {
        GpmProjectPlanEntity mpmProjectPlanEntity = gpmProjectPlanService.queryById(sourceid);
        //查看是否有退回，有退回则更新
        int recordCount = this.getCount("sourceid="+sourceid + " and sourcetype='"+ GpmProjectPlanEntity.tableName +"' and version="
                +mpmProjectPlanEntity.getVersion() + " and state=2");
        if(recordCount>0) {
            Map<String,Object> updateMap = new HashMap<String,Object>();
            updateMap.put("state",1);
            //先删除退回的数据
            this.updateByWhere(updateMap,"sourceid="+sourceid + " and sourcetype='"+ GpmProjectPlanEntity.tableName +"' and version="
                    +mpmProjectPlanEntity.getVersion() + " and state=2");
        }
        //再添加
        StringBufferProxy whereSql = new StringBufferProxy();
        whereSql.appendSingle(" {0} = '{1}' and state = '9' ", GpmProjectPlanEntity.FieldProjectcode,
                mpmProjectPlanEntity.getProjectcode());
        // 判断是否是二次策划
        return gpmProjectPlanService.getCount(whereSql.toString()) > 0;
    }

    /**
     * @author: chengengwei
     * @date: 2021-09-13
     * @description: 获取上个版本单据的id
     * @modify:
     */
    @Override
    public void addLastVersionInfo(Map<String, Object> map) {
        StringBufferProxy sql = new StringBufferProxy();
        String sourcetype = ConvertUtil.convertToString(map.get(GpmProjectUniversalChangeEntity.FieldSourcetype));
        String projectcode = ConvertUtil.convertToString(map.get("projectcode"));
        if (!ChangeSourceTypeEnum.UniversalChange.equals(sourcetype)) {
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("sourcetype", sourcetype);
            paramsMap.put("projectcode", projectcode);
            paramsMap.put("sourceid", ConvertUtil.convertToString(map.get("sourceid")));
            paramsMap.put("version", ConvertUtil.convertToInt(map.get("version"))-1);
            paramsMap.put("projectcodefield", "projectcode");
            // 查询同一个项目中当前单据的上一个记录
            List<Map<String, Object>> idList = this.queryMap(paramsMap, "queryLastRecordId");
            if (!idList.isEmpty()) {
                map.put("lastsourceid", idList.get(0).get("id"));
            }
        }
    }

    /**
     * @description: 是否待审批
     * @param map
     * @return void
     * @author: wangxinhua
     * @date: 2021/12/22 14:33
     * @modify:
     */
    @Override
    public void isInApprovalList(Map<String, Object> map) {
        String sourceType = ConvertUtil.convertToString(map.get("sourcetype"));
        String sourceId = ConvertUtil.convertToString(map.get("sourceid"));
        String id = ConvertUtil.convertToString(map.get("id"));
        String state = ConvertUtil.convertToString(map.get("state"));
        List<CboApprovalNodeInsEntity> countList = new ArrayList<>();
        if("1".equals(state)) {
            if(GpmProjectHistoryEntity.tableName.equals(sourceType)) {
                countList = cboApprovalNodeInsService.queryByWhere("sourceid=(select max(id) from GPMWfForm where sourcetype='GpmProjectHistory' and sourceid="+sourceId+")"
                        + " and sourcetype='GpmWfForm' and state=1" +" and approvaluserid=" + this.getSessionUserBean().getUser().getId());
            } else if(GpmProjectAppointmentEntity.tableName.equals(sourceType)) {
                countList = cboApprovalNodeInsService.queryByWhere("sourceid="+ sourceId +" and approvaluserid=" + this.getSessionUserBean().getUser().getId()
                        + " and sourcetype='"+sourceType+"' and state=1");
            } else if(GpmProjectPlanEntity.tableName.equals(sourceType)) {
                countList = cboApprovalNodeInsService.queryByWhere("sourceid="+ sourceId +" and approvaluserid=" + this.getSessionUserBean().getUser().getId()
                        + " and sourcetype='"+sourceType+"' and state=1");
            } else {
                countList = cboApprovalNodeInsService.queryByWhere("sourceid="+ id +" and approvaluserid=" + this.getSessionUserBean().getUser().getId()
                        + " and sourcetype='"+ GpmProjectUniversalChangeEntity.tableName+"' and state=1");
            }
        }
        if(countList.size() > 0) {
            map.put("isinapproval","1");
            map.put("nodeinsid",countList.get(0).getId());
        } else {
            map.put("isInApproval","0");
            map.put("nodeinsid","");
        }
    }

    /**
     * @description: 删除之前，删除主变更信息以及主表数据
     * @param whereSql
     * @return void
     * @author: wangxinhua
     * @date: 2022/2/12 8:50
     * @modify:
     */
    @Override
    protected void deleteBefore(String whereSql) {
        List<GpmProjectUniversalChangeEntity> deleteEntities = this.queryByWhere(whereSql);
        for (GpmProjectUniversalChangeEntity delItem : deleteEntities) {
            if(GpmProjectHistoryEntity.tableName.equals(delItem.getSourcetype())) {
                gpmProjectHistoryService.deleteById(ConvertUtil.convertToString(delItem.getSourceid()));
                gpmWfFormService.deleteByWhere(" SOURCEID="+delItem.getSourceid()+" and SOURCETYPE='GpmProjectHistory'");
            } else if(GpmProjectAppointmentEntity.tableName.equals(delItem.getSourcetype())) {
                gpmProjectAppointmentService.deleteByWhere( "id="+ConvertUtil.convertToString(delItem.getSourceid()));
            } else if(GpmProjectPlanEntity.tableName.equals(delItem.getSourcetype())) {
                gpmProjectPlanService.deleteByWhere( "id="+ConvertUtil.convertToString(delItem.getSourceid()));
            }
        }
    }
}
